package com.yanqu.road.server.cmd.activity.ghost;

import com.yanqu.road.pb.activity.GhostActivityProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.cross.battle.ghost.GhostActivity;
import com.yanqu.road.server.manager.cross.battle.ghost.GhostMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

@Cmd(code = CrossProtocol.C2_GHOST_ACTIVITY_GET_UNION_NEWS, desc = "跨服获取商会情报")
public class CrossGhostGetUnionNewsCmd extends CrossCommand {

    int activityId;
    long serverId;
    long userId;
    int type;
    String unionUid;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        GhostActivityProto.CrossGhostGetUnionNewsReqMsg reqMsg = GhostActivityProto.CrossGhostGetUnionNewsReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        serverId = reqMsg.getServerId();
        userId = packet.getPlayerId();
        type = reqMsg.getType();
        unionUid = reqMsg.getUnionUid();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        GhostActivity activity = GhostMgr.getActivity(activityId);
        if (activity == null) {
            ret = GameErrorCode.E_GHOST_ACTIVITY_NO_OPEN;
            return;
        }

        List<GhostActivityProto.GhostUnionNewsMsg> unionNewsMsgList = activity.getUnionNewsMsgList(unionUid, type);

        GhostActivityProto.CrossGhostGetUnionNewsRespMsg.Builder builder = GhostActivityProto.CrossGhostGetUnionNewsRespMsg.newBuilder();
        builder.addAllNewsList(unionNewsMsgList);
        MessageHelper.sendPacket(serverId, userId, YanQuMessageUtils.buildMessage(GameProtocol.S_GHOST_GET_UNION_NEWS_FROM_CROSS, builder));

    }

    @Override
    public void sendData() {

    }
}
